package org.loong.crypto.common.exception;

public class InvalidKeyLengthException extends KeyException {

    private static final long serialVersionUID = 1L;

    /**
     * The expected key length.
     */
    private final int expectedLength;

    /**
     * Creates a new key length exception.
     *
     * @param message The exception message.
     */
    public InvalidKeyLengthException(final String message) {
        super(message);
        expectedLength = 0;
    }

    /**
     * Creates a new key length exception.
     *
     * @param expectedLength The expected key length in bits, zero if not specified.
     */
    public InvalidKeyLengthException(final int expectedLength) {
        super((expectedLength > 0) ? "The expected key length is " + expectedLength + " bits" : "Unexpected key length");
        this.expectedLength = expectedLength;
    }

    /**
     * Returns the expected key length.
     *
     * @return The expected key length in bits, zero if not specified.
     */
    public int getExpectedKeyLength() {
        return expectedLength;
    }
}
